<header>
<div class="b_top">
    <a href="/" class="logo"><img src="<?php echo IMG_PATH ?>index/logo.png"/></a>
    <div class="game_info">
        <div class="price_title">
            <h2>
                <a href="javascript:;"  class="bj <?php if(MODEL_NAME != 'records'){ echo 'on'; } ?>"  data-url="<?php echo U('index/search') ?>">游戏比价</a>
                <a href="javascript:;"  class="hq <?php if(MODEL_NAME == 'records'){ echo 'on'; } ?>"  data-url="<?php echo U('index/records') ?>">历史行情</a>
            </h2>
            <div class="p_than">
                <div class="p_type">
                    <a href="javascript:;" id="gameName"><?php echo isHave($game_name) ? $game_name : '游戏名称'; ?></a>
                    <a href="javascript:;" id="gameArea"><?php echo isHave($area_name) ? $area_name : '游戏大区'; ?></a>
                    <a href="javascript:;" id="gameServer"><?php echo isHave($server_name) ? $server_name : '游戏服务器'; ?></a>
                    <a href="javascript:;" id="gameType"><?php echo isHave($type_name) ? $type_name : '物品类型'; ?></a>
                    <a href="javascript:;" id="ident">
                        <?php 
                            if(isHave($cr)){ 
                                if($cr == 'buyer'){ echo '买家'; }elseif($cr == 'seller'){ echo '卖家'; } 
                            }else{
                                echo '交易身份';
                            }    
                        ?>
                    </a>
                </div>
                <button style="cursor:pointer;" id="subBtn">立即查看</button>
            </div>
        </div>
        <div class="gameBox">
        <div class="game_n">
            <div class="g_tit">
                <h2>
                    <span>历史选择：</span>
                    <span class="history">
                      <?php foreach ($history_games as $vo): ?>
                        <a href="javascript:;" onclick="chooseGame(this)" data-id="<?php echo $vo['id'] ?>" data-name="<?php echo $vo['name'] ?>" data-abri="<?php echo $vo['abridge'] ?>"><?php echo $vo['name'] ?></a>
                      <?php endforeach ?>
                    </span>
                </h2>
                <!-- 检索 -->
                <div class="g_search">
                    <!-- <input type="text">
                    <a href="javascript:;">快速搜索</a> -->
                </div>
                <div class="cancel">X</div>
                <!-- END -->
            </div>
            <div class="g_hot">
                <div class="g_hot_t">
                    <a href="javascript:;" class="hot on">热门游戏</a>
                    <?php foreach ($letters as $k => $v): 
                            if(isset($games[$v]) && $games[$v]){ 
                    ?>
                        <a href="javascript:;"><?php echo $v; ?></a>
                    <?php 
                        } 
                        endforeach 
                    ?>
                </div>
                <!-- 热门游戏 -->
                <div class="g_name_list active" >
                    <?php foreach ($games['hot'] as $key => $vo): ?>
                        <a href="javascript:;">
                            <div class="g_one" onclick="chooseGame(this)" data-id="<?php echo $vo['id'] ?>" data-name="<?php echo $vo['name'] ?>" data-abri="<?php echo $vo['abridge'] ?>">
                                <img src="<?php echo IMG_PATH ?>index/games/<?php echo $vo['abridge'] ?>.png"/>
                                <p><?php echo $vo['name'] ?></p>
                            </div>
                        </a>
                    <?php endforeach ?>
                </div>
                <?php unset($games['hot']); ?>
                <?php foreach ($games as $k => $val): 
                        if(!empty($val)){ 
                ?>
                    <div class="g_name_list">
                        <?php foreach ($val as $_game): ?>
                            <a href="javascript:;">
                                <div class="g_one" onclick="chooseGame(this)" data-id="<?php echo $_game['id'] ?>" data-name="<?php echo $_game['name'] ?>" data-abri="<?php echo $_game['abridge'] ?>">
                                    <img src="<?php echo IMG_PATH ?>index/games/<?php echo $_game['abridge'] ?>.png"/>
                                    <p><?php echo $_game['name'] ?></p>
                                </div>
                            </a>
                        <?php endforeach ?>
                    </div>
                <?php 
                    }
                    endforeach 
                ?>
            </div>
        </div>

        <div class="game_n">
            <div class="g_tit">
                <h2>
                    <span>请选择游戏区：</span>
                </h2>
                <div class="cancel">X</div>
            </div>
            <div class="g_hot_wr area1">
                <?php if(isHave($areas)){ ?>
                    <?php foreach ($areas as $k => $v): ?>
                        <div class="p_one <?php if($v['id'] == $area_id){ echo 'on'; } ?>" onclick="getServer(this);" data-id="<?php echo $v['id'] ?>" data-name="<?php echo $v['area_name'] ?>">
                            <b></b>
                            <a href="javascript:;"><?php echo $v['area_name'] ?></a>
                        </div>
                    <?php endforeach ?>
                <?php } ?>
            </div>
        </div>
        <div class="game_n">
            <div class="g_tit">
                <h2>
                    <span>请选择游戏服务器：</span>
                </h2>
                <div class="cancel">X</div>
            </div>
            <div class="g_hot_wr area2">
                <?php if(isHave($servers)){ ?>
                    <?php foreach ($servers as $k => $v): ?>
                        <div class="p_one <?php if($v['abridge'] == $ar){ echo 'on'; } ?>" onclick="getGameType(this);" data-name="<?php echo $v['server_name'] ?>" data-abri="<?php echo $v['abridge'] ?>">
                            <b></b>
                            <a href="javascript:;"><?php echo $v['server_name'] ?></a>
                        </div>
                    <?php endforeach ?>
                <?php } ?>
            </div>
        </div>
        <div class="game_n ">
            <div class="g_tit">
                <h2>
                    <span>请选择游戏物品类型：</span>
                </h2>
                <div class="cancel">X</div>
            </div>
            <div class="g_hot_wr area3">
                <?php if(isHave($types)){ ?>
                    <?php foreach ($types as $k => $v): ?>
                        <div class="p_one <?php if($v['abridge'] == $ty){ echo 'on'; } ?>" onclick="getIdent(this)" data-name="<?php echo $v['name'] ?>" data-abri="<?php echo $v['abridge'] ?>">
                            <b></b>
                            <a href="javascript:;"><?php echo $v['name'] ?></a>
                        </div>
                    <?php endforeach ?>
                <?php } ?>
            </div>
        </div>
        <div class="game_n">
            <div class="g_tit">
                <h2>
                    <span>请选择交易身份：</span>
                </h2>
                <div class="cancel">X</div>
            </div>
            <div class="g_hot_wr area4">
                <div class="p_one <?php if($cr == 'buyer'){ echo 'on'; } ?>" data-name="买家" data-abri="buyer"  onclick="chooseIdent(this)">
                    <b></b>
                    <a href="javascript:;">买家</a>
                </div>
                <div class="p_one <?php if($cr == 'seller'){ echo 'on'; } ?>" data-name="卖家" data-abri="seller" onclick="chooseIdent(this)">
                    <b></b>
                    <a href="javascript:;">卖家</a>
                </div>
            </div>
        </div>
    </div>
    </div>
</div>
<form id="postForm" action="<?php echo U('index/search') ?>" method="get">
    <!-- 游戏编码 -->
    <input type="hidden" name="gm" value="<?php echo $gm ?>"> 
    <!-- 区服编码 -->
    <input type="hidden" name="ar" value="<?php echo $ar ?>">
    <!-- 物品类型 -->
    <input type="hidden" name="ty" value="<?php echo $ty ?>">
    <!-- 身份 -->
    <input type="hidden" name="cr" value="<?php echo $cr ?>">
</form>
</header>
<script>
    var mode = "<?php echo MODEL_NAME ?>";
    $(function(){
        $(".p_type a").click(function(){
            var num=$(this).index();
            $(".game_n").eq(num).addClass("active").siblings(".game_n").removeClass("active");
            $(".gameBox").get(0).className = 'gameBox';
            $(".gameBox").addClass("wr"+(num*1+1));
        });

        $(".g_hot_t a").click(function(){
            $(this).addClass("on").siblings("a").removeClass("on");
            var num=$(this).index();
            $(".g_name_list").eq(num).addClass("active").siblings(".g_name_list").removeClass("active");
        })

        //提交表单
        $("#subBtn").click(function(){
            if(mode == 'records' && $('.hq').hasClass('on')) {
                return;
            }else{
                var g = $("input[name=gm]").val();
                var a = $("input[name=ar]").val();
                var t = $("input[name=ty]").val();
                var c = $("input[name=cr]").val();
                if(!g || !a || !t || !c) {
                    return false;
                }
                //历史详情需要登录
                if($(".hq").hasClass('on')) {
                    var isLogin = "<?php echo isHave(user::$userInfo['uid']) ? 1 : 2; ?>";
                    if(isLogin == 2) {
                        var refer_url = "<?php echo U('index/records') ?>?"+'gm='+g+"&ar="+a+"&ty="+t+"&cr="+c;
                        $("#login").click();
                        $('#refer').val(encodeURIComponent(refer_url));
                        return false;
                    }
                }
                $("#postForm").submit();
            }
        });

        $(".cancel").click(function(){
            $(this).parents(".game_n ").removeClass("active");
            $(".gameBox").get(0).className = 'gameBox';
        })

        
        $(".price_title h2 a").click(function(){
            $(this).addClass("on").siblings("a").removeClass("on");
            var url = $(this).attr('data-url');
            $("#postForm").attr('action' , url);
        })
    });

    // 选择游戏
    function chooseGame(obj) {
        $("#gameName").text($(obj).attr('data-name'));
        $("#gameArea").text("游戏大区");
        $("#gameServer").text("游戏服务器");
        $("#gameType").text("物品类型");
        $(".area2").html("");
        //清空表单
        resetForm();
        //加入表单
        $("input[name=gm]").val($(obj).attr('data-abri'));
        var game_id = $(obj).attr('data-id');
        $.getJSON("<?php echo U('index/getAreaByGameId') ?>", {game_id : game_id} , function(result){
            if(result.status == 1){
                $(".area1").html(result.data);
            }
        });
        //获取物品类型
        $.getJSON("<?php echo U('index/getStdmodeByGameId') ?>", {game_id : game_id}, function(result){
            if(result.status == 1) {
                $(".area3").html(result.data);
            }
        });
        //设置搜索历史
        $.getJSON("<?php echo U('index/setHistory') ?>" , {game_id : game_id} , function(result){
            if(result.status == 1) {
                $(".history").html(result.data);
            }
        });

        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr2");
    }

    //获取服信息
    function getServer(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#gameArea").text($(obj).attr('data-name'));
        $("#gameServer").text("游戏服务器");
        //清除
        $("input[name=ar]").val(''); 
        var area_id = $(obj).attr('data-id');
        $.getJSON("<?php echo U('index/getServerByAreaId') ?>" , {area_id , area_id}, function(result){
            if(result.status == 1){
                $(".area2").html(result.data);
            }
        });
        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr3");
    }


    //物品类型
    function getGameType(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#gameServer").text($(obj).attr('data-name'));
        //加入表单
        $("input[name=ar]").val($(obj).attr('data-abri'));
        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr4");
        if(mode == 'records' && $('.hq').hasClass('on')){ 
            areas = $(obj).attr('data-abri');
            getData();
        }
    }
    

    
    //选择身份
    function getIdent(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#gameType").text($(obj).attr('data-name'));
        //加入表单
        $("input[name=ty]").val($(obj).attr('data-abri'));
        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr5");
    }


    //提交检索信息
    function chooseIdent(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#ident").text($(obj).attr('data-name'));
        //加入表单
        $("input[name=cr]").val($(obj).attr('data-abri'));
        $(obj).parents(".game_n").removeClass("active");
        $(".gameBox").removeClass("wr5");
        var g = $("input[name=gm]").val();
        var a = $("input[name=ar]").val();
        var t = $("input[name=ty]").val();
        var c = $("input[name=cr]").val();
        if(!g || !a || !t || !c) {
            return false;
        }
        //历史详情需要登录
        if($(".hq").hasClass('on')) {
            var isLogin = "<?php echo isHave(user::$userInfo['uid']) ? 1 : 2; ?>";
            if(isLogin == 2) {
                var refer_url = "<?php echo U('index/records') ?>?"+'gm='+g+"&ar="+a+"&ty="+t+"&cr="+c;
                $("#login").click();
                $('#refer').val(encodeURIComponent(refer_url));
                return false;
            }
        }
        $("#postForm").submit();
    }

    //清空表单
    function resetForm() {
        $(":input","#postForm")
        .not(":button",":reset","hidden","submit")
        .val("")
        .removeAttr("checked")
        .removeAttr("selected");
    }
</script>